package com.yanlin.servicepassengeruser.controller;

import com.yanlin.internalcommon.dto.ResponseResult;
import com.yanlin.internalcommon.request.VerificationCodeDTO;
import com.yanlin.servicepassengeruser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>标题：UserController</p>
 * <p>功能：</p>
 * <p>
 * 其他说明：
 * </p>
 * <p>审核：</p>
 * <p>重构：</p>
 * <p>创建日期：2025-06-06 06:23</p>
 *
 * @author yanlin
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据手机号插入用户（注册）
     *
     * @param verificationCodeDTO
     * @return
     */
    @PostMapping("/user")
    public ResponseResult loginOrRegister(@RequestBody VerificationCodeDTO verificationCodeDTO) {

        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        System.out.println("登陆手机号 = " + passengerPhone);

        return userService.loginOrRegister(passengerPhone);
    }

    @GetMapping("/user/{phone}")
    public ResponseResult getUser(@PathVariable String phone) {
        return userService.getUserByPassengerPhone(phone);
    }
}